let v = new Vue({
    el:'#main-container',
    data:{
        user:{},
        ifRegister:true,
        usernameInput:'form-group',
        emailInput:'form-group',
    },
    methods:{
        checkRegister:function () {
            axios({
                url:'checkRegister',
                method:'post',
                data:this.user,
            }).then(resp => {
                if(resp.data.success){
                    //可以注册
                    this.usernameInput = 'form-group';
                    this.emailInput = 'form-group';
                    this.ifRegister = true;
                }else{
                    this.ifRegister = false;
                    if(resp.data.obj == 1){
                        //账号已注册
                        this.usernameInput = 'form-group has-error';
                    }else if(resp.data.obj == 2){
                        //邮箱已注册
                        this.emailInput = 'form-group has-error';
                    }else{
                        //都已经注册
                        this.usernameInput = 'form-group has-error';
                        this.emailInput = 'form-group has-error';
                    }

                }
            }).catch(error => {
                layer.msg(error.message);
            })
        },
        doRegister:function () {
            if(this.ifRegister){
                //可以注册
                if(this.user.password != this.user.password2){
                    layer.msg('两次密码不一致！');
                }else {
                    axios({
                        url:'doRegister',
                        data:this.user,
                        method: 'post',
                    }).then(resp => {
                        if(resp.data.success){
                            location.href = 'index.html';
                        }else {
                            layer.msg(resp.data.msg);
                        }
                    }).catch(error => {
                        layer.msg(error.message);
                    })
                }
            }else{
                layer.msg('账号或邮箱以被注册')
            }
        }
    },
    created:function () {

    }
})